package com.mango.request;

import android.support.annotation.Nullable;

import com.mango.request.beans.UserLoginBean;
import com.mango.volley.Response;

import org.json.JSONException;
import org.json.JSONObject;

public class ReqMgUserLogin extends ReqMango<UserLoginBean> {
    public ReqMgUserLogin(String appID, String appKey, String uid,
                       @Nullable Response.Listener<UserLoginBean> listener,
                       @Nullable Response.ErrorListener errorListener) {
        super("api/wall/userlogin", new Object[]{"uid", uid, "appId", appID,
                "timeStamp", System.currentTimeMillis(), null, appKey}, listener, errorListener);
    }

    @Override
    protected String getJsonParams() {
        return null;
    }

    @Override
    protected UserLoginBean parseJsonResult(String json) throws JSONException {
        JSONObject data = new JSONObject(json).getJSONObject("data");

        JSONObject user = data.getJSONObject("user");
        JSONObject integral = data.getJSONObject("integral");

        UserLoginBean result = new UserLoginBean();

        result.user = new UserLoginBean.UserBean();
        result.user.uid = user.optString("uid");
        result.user.integral = user.optDouble("integral");

        result.integral = new UserLoginBean.IntegralBean();
        result.integral.Name = integral.optString("Name");
        result.integral.icon = integral.optString("icon");
        result.integral.ratio = integral.optString("ratio");

        return result;
    }
}
